package com.cx.config.properties;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author dijia
 **/
@Component
@Data
@ConfigurationProperties(prefix = DomainMappingProperties.PREFIX)
@Slf4j
public class DomainMappingProperties {

    public static final String PREFIX="domain-mapping";

    private List<MapConfig> mappingList;


    public Integer getTenantIdByDomain(String currentDomain){
        for(MapConfig config:this.mappingList){
            if(StringUtils.equals(config.getDomain(),currentDomain)){
                return config.getTenantId();
            }
        }
        throw new RuntimeException("租户系统未找到");//启用多租户放开
    }

    @Data
    static class MapConfig{
        private String domain;
        private Integer tenantId;
    }
}
